<?php

namespace Nece\Sdk\Coze\Entity;

/**
 * 消息体
 *
 * @author gjw
 * @created 2025-04-24 16:52:04
 */
class Message
{
    // 消息类型
    const TYPE_TEXT = 'text';
    const TYPE_IMAGE = 'image';

    private $type_fields = array(
        self::TYPE_TEXT => 'text',
        self::TYPE_IMAGE => 'file_id'
    );

    private $type;
    private $content;

    public function __construct($content, $type = self::TYPE_TEXT)
    {
        $this->type = $type;
        $this->content = $content;
    }

    public function toArray()
    {
        $field = $this->type_fields[$this->type];
        return array(
            'type' => $this->type,
            $field => $this->content
        );
    }

    public function toJsonString()
    {
        return json_encode($this->toArray());
    }

    public function toString()
    {
        return $this->content;
    }
}
